﻿using Newtonsoft.Json;
using Simple.Services;
using Simple.Services.System.Jobs;
using Simple.Services.System.Report.Danger;
using TaskStatus = Simple.Services.System.Jobs.TaskStatus;

namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 隐患报表分析
/// </summary>
[Route("QHSEDangerReport/[action]")]
[ApiController]
public class QHSEDangerReportController : ControllerBase
{
    private readonly QHSEDangerReportService _reportService;


    public QHSEDangerReportController(QHSEDangerReportService reportService)
    {
        _reportService = reportService;
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult CleanCompletedTasks()
    {

        // 将任务状态记录为 "进行中"
        var data = TaskManager.CleanCompletedTasks();

        // 返回任务 ID
        return Ok(new { data });
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult CleanFailedTasks()
    {

        // 将任务状态记录为 "进行中"
        var data = TaskManager.CleanFailedTasks();

        // 返回任务 ID
        return Ok(new { data });
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableDangerCheckCount([FromBody] QHSETotalInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }

    private async Task TableDangerCheckCountAsync(string taskId, QHSETotalInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerTotalCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患总数表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患总数表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerCheckCount([FromBody] QHSETotalInputModel inputModel)
    {
        var res = await _reportService.TableDangerTotalCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }

    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareDangerCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareDangerCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareDangerCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareDangerDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareDangerCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患查纠数量对比图
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareDangerCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患查纠数量对比图
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareDangerCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareDangerDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTabelSelfDangerCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TabelSelfDangerCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TabelSelfDangerCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTabelSelfDangerCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-二级单位表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableSelfDangerCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-二级单位表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableSelfDangerCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }

    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfDangerTypeCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfDangerTypeCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfDangerTypeCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfDangerTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfDangerTypeCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    } /// <summary>
      /// 报表-违章级别对比-自查
      /// </summary>
      /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfDangerTypeCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患级别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfDangerTypeCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfDangerTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseDangerTypeCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseDangerTypeCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseDangerTypeCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseDangerTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseDangerTypeCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章级别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseDangerTypeCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患级别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseDangerTypeCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseDangerTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableDangerTypeCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerTypeCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableDangerTypeCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerTypeCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患级别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerTypeCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患级别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerTypeCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }

    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfDangerCategoryCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfDangerCategoryCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfDangerCategoryCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfDangerCategoryCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfDangerCategoryCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患类别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfDangerCategoryCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患类别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfDangerCategoryCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfDangerCategoryCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseDangerCategoryCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseDangerCategoryCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseDangerCategoryCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseDangerCategoryCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseDangerCategoryCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章类别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseDangerCategoryCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患类别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseDangerCategoryCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseDangerCategoryCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }

    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableDangerCategoryCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerCategoryCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableDangerCategoryCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerCategoryCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerCategoryCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患类别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerCategoryCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患类别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerCategoryCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerCategoryCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    /// <summary>
    /// 报表-直线部门对比-自查
    /// </summary>
    /// <returns></returns>
    /// [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    [HttpPost]
    public IActionResult StartCompareSelfDangerDepartmentCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为"进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfDangerDepartmentCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfDangerDepartmentCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfDangerDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfDangerDepartmentCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfDangerDepartmentCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseDangerDepartmentCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseDangerDepartmentCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseDangerDepartmentCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseDangerDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseDangerDepartmentCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患归属部门对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseDangerDepartmentCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患归属部门对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseDangerDepartmentsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseDangerDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableTableDangerDirectDepartmentCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerDirectDepartmentCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableDangerDirectDepartmentCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerDirectDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerDirectDepartmentCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患归属部门对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerDirectDepartmentCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患归属部门对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerDirectDepartmentCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerDirectDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfDangerWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfDangerWorkSpecialtyCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfDangerWorkSpecialtyCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfDangerWorkSpecialtyCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfDangerWorkSpecialtyCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患专业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfDangerWorkSpecialtyCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患专业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfDangerWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfDangerWorkSpecialtyCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseDangerWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseDangerWorkSpecialtyCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseDangerWorkSpecialtyCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseDangerWorkSpecialtyCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseDangerWorkSpecialtyCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患专业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseDangerWorkSpecialtyCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患专业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseDangerWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseDangerWorkSpecialtyCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableDangerWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerWorkSpecialtyCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableDangerWorkSpecialtyCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerWorkSpecialtyCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerWorkSpecialtyCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患专业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerWorkSpecialtyCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患专业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerWorkSpecialtyCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfDangerKeyWorkCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfDangerKeyWorkCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfDangerKeyWorkCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfDangerKeyWorkCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfDangerKeyWorkCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患关键作业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfDangerKeyWorkCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患关键作业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfDangerKeyWorkCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfDangerKeyWorkCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseDangerKeyWorkCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseDangerKeyWorkCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseDangerKeyWorkCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseDangerKeyWorkCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseDangerKeyWorkCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患关键作业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseDangerKeyWorkCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患关键作业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseDangerKeyWorkCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseDangerKeyWorkCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableDangerKeyWorkCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerKeyWorkCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableDangerKeyWorkCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerKeyWorkCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerKeyWorkCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患关键作业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerKeyWorkCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患关键作业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerKeyWorkCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerKeyWorkCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfDangerHSECheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfDangerHSECheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfDangerHSECheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfDangerHSECheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfDangerHSECheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患体系要素对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfDangerHSECheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患体系要素对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfDangerHSECheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfDangerHSECheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseDangerHSECheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseDangerHSECheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseDangerHSECheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseDangerHSECheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseDangerHSECheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患体系要素对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseDangerHSECheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患体系要素对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseDangerHSECheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseDangerHSECheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableDangerHSECheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableDangerHSECheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableDangerHSECheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableDangerHSECheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableDangerHSECheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-隐患体系要素对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableDangerHSECheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-隐患体系要素对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableDangerHSECheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableDangerHSECheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
}

